package com.qf.work20250111;

import java.lang.reflect.Field;

/**
 * @author zdl
 * @date 2025/1/11
 */
public class Demo4 {
    public static void main(String[] args) throws NoSuchFieldException, InstantiationException, IllegalAccessException {
        // 反射获取 属性
        Class<Person> pc = Person.class;
        Field field1 = pc.getDeclaredField("name");
        Person person = pc.newInstance();
        field1.set(person,"Rose");
        Field field2 = pc.getDeclaredField("age");
        field2.setAccessible(true);
        field2.set(person,22);
        System.out.println(person);
    }
}
